package middle.id_1_100;

import java.util.Stack;

public class hua4 {

    public static void main(String[] args) {
        String s= "9,3,5,-,2,*,+";
        System.out.println(calcExpression(s));
    }


    // 待实现函数，在此函数中填入答题代码
    private static int calcExpression(String expression) {
        String[] tokens = expression.split(",");
        Stack<Long> sta=new Stack<>();

        for(int i=0;i<tokens.length;i++){
            if(tokens[i].equals("+") || tokens[i].equals("-") || tokens[i].equals("*") || tokens[i].equals("/") ){
                long  num1 = sta.pop();
                long  num2 = sta.pop();
                if(tokens[i].equals("+") ) sta.push(num2+num1);
                if(tokens[i].equals("-") ) sta.push(num2-num1);
                if(tokens[i].equals("*") ) sta.push(num2*num1);
                if(tokens[i].equals("/") ) sta.push(num2/num1);
            }else{
                long l = Long.parseLong(tokens[i]);
                sta.push(l);
            }
        }

        long re = sta.peek();
        return (int) re;

    }

}
